home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7188 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  62 lines

  1. Path: news.wyoming.com!usenet
  2. From: dcromley@wyoming.com (Dave Cromley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help on assignment
  5. Date: 22 Feb 1996 05:02:28 GMT
  6. Organization: wyoming.com LLC
  7. Message-ID: <4ggtd4$hg@horn.wyoming.com>
  8. NNTP-Posting-Host: cys-cap-10.wyoming.com
  9. Mime-Version: 1.0
  10. X-Newsreader: WinVN 0.99.2
  11.  
  12. >.. Don't think I recieved enough information..
  13.  
  14. I'm probably not doing you a favor by giving you this,
  15. but I am learning C++ pretty well from your questions.
  16. I hope you can get going in your book.
  17.  
  18. I wonder if 'polymorphism' is the word for subr1--
  19. having two versions of subr1, depending on the call.
  20. I also wonder if you could do this in one version and a
  21. parameter check somehow.
  22.  
  23. 'Zerosmaller' shows reference parameters.  I hope your book
  24. explains that.  In C, you would do 'zerosmaller(&i5, &i7)'
  25. and the prog would be 'zerosmaller(*i1, *i2) { ..'.
  26.  
  27.   Dave C.
  28.  
  29. #include <iostream.h>
  30.  
  31. void subr1(char *s);            //subr1 - 1st
  32. void subr1(char *s, int n);     //subr1 - 2nd
  33. void zerosmaller(int &i1, int &i2);  // zerosmaller
  34.  
  35. void main() {
  36.   subr1("Print this once");
  37.   subr1("Print this three times", 3);
  38.   int i5 = 5, i7 = 7;
  39.   zerosmaller(i5, i7);
  40.   cout << "i5 = " << i5 << ", i7 = " << i7 << endl;
  41.   }
  42.  
  43. void subr1(char *s) {  // subr1 - 1st
  44.   cout << s << endl;
  45.   }
  46.  
  47. void subr1(char *s, int n) {  // subr1 - 2nd
  48.   while (n-- > 0) {
  49.     cout << s << endl;
  50.     }
  51.   }
  52.  
  53. void zerosmaller(int &i1, int &i2) {  // zerosmaller - reference args
  54.   if      (i1 < i2) i1 = 0;
  55.   else if (i1 > i2) i2 = 0;
  56.   else {
  57.     i1 = 0; i2 = 0;
  58.     }
  59.   }
  60.  
  61.  
  62.